home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / osr5 / sco / scripts / manifest < prev    next >
Encoding:
Korn shell script  |  1997-08-26  |  3.5 KB  |  144 lines

  1. #!/bin/ksh
  2. # @(#) manifest.ksh 2.2 97/05/11
  3. # 93/06/18 john h. dubois iii (john@armory.com)
  4. # 94/02/15 Added multiple compilers option.
  5. # 94/05/19 Added option of giving args to compiler.
  6. # 96/01/06 5.0 port: If on >= 5.0, give -# to cc; also remove '' from -D output
  7. # 96/01/19 Changed default tmpdir to home dir for safety
  8. # 96/02/02 Remove object file too
  9. # 97/05/11 Cleaned up/fixed argument processing
  10.  
  11. # Sets _OSRelease to the entire OS release (e.g. 3.2v5.0.0}
  12. # Sets _OSVersion to the version part (e.g. 5.0.0)
  13. # Returns the major part of the version (e.g. 5)
  14. # If an OSVersion value is given as an arg, returns 0 if the system OS version
  15. # is lexicographically less than it; 1 if they are equal; 2 if the system OS
  16. # version is greater.
  17. function OSVersion {
  18.     typeset arg=$1
  19.     if [ -z "$_OSRelease" ]; then
  20.     # Name of release field is different in different langs
  21.     set -- $(LANG=english_us.ascii uname -X)
  22.     while [ "$1" != Release -a $# -ge 3 ]; do
  23.         shift 3
  24.     done
  25.     [ $# -lt 3 ] && return 1
  26.     _OSRelease=$3
  27.     _OSVersion=${3##*v}
  28.     fi
  29.     [ -z "$arg" ] && return ${_OSVersion%%.*}
  30.     [[ "$_OSVersion" > "$arg" ]] && return 2
  31.     [[ "$_OSVersion" < "$arg" ]] && return 0
  32.     return 1
  33. }
  34.  
  35. typeset -L20 word
  36. typeset -i i=0
  37. Debug=false
  38.  
  39. name=${0##*/}
  40. Usage="Usage: $name [-xh] [compiler] [-compiler-args]"
  41.  
  42. set -A args -- "$@"    # save args
  43.  
  44. # If on a release earlier than 5.0, use uSoft flag (-z); else at&t flag (-#).
  45. # Assumes the compiler appropriate to the release is installed as cc.
  46. OSVersion 5.0.0 && set -A comp -- cc -z || set -A comp -- cc -#
  47. set -A comp -- "${comp[@]}" gcc -v icc -#
  48. typeset -i numcomp=${#comp[*]}/2 i
  49.  
  50. # Use leading : so that getopts will not complain if unknown option given
  51. while getopts :hx opt "${args[@]}"; do
  52.     case $opt in
  53.     h)
  54.     print -r -- \
  55. "$name: print compiler manifest defines.
  56. $Usage
  57. If no compiler name is given, the standard compiler (cc) is used.
  58. If any arguments are given, they are passed to the compiler.  For example,
  59. $name cc -dos
  60. can be used to get the manifest defines for the DOS cross compiler.
  61. The compilers that $name knows how to extract manifest defines from are:"
  62.     i=0
  63.     while [ i -lt numcomp ]; do
  64.     print -rn -- "${comp[i*2]} "
  65.     let i+=1
  66.     done
  67.     print -r -- "
  68. Options:
  69. -h: Print this help.
  70. -x: Turn on debugging."
  71.     exit 0
  72.     ;;
  73.     x)
  74.     Debug=true
  75.     ;;
  76.     ?)
  77.     break
  78.     ;;
  79.     esac
  80. done
  81.  
  82. # remove args that were options
  83. let OPTIND=OPTIND-1
  84. shift $OPTIND
  85.  
  86. $Debug && print -ru2 -- "Non-option arguments: $*"
  87.  
  88. if [[ $# -eq 0 || "$1" = -* ]]; then
  89.     Compiler=cc
  90. else
  91.     Compiler=$1
  92.     shift
  93. fi
  94. compArgs="$*"
  95. Tail=${Compiler##*/}
  96. set -- "${comp[@]}"
  97. while [ $# -gt 0 ]; do
  98.     if [ "$1" = "$Tail" ]; then
  99.     Compiler="$1 $compArgs $2"
  100.     break
  101.     fi
  102.     shift 2
  103. done
  104.  
  105. if [ -z "$Compiler" ]; then
  106.     print -u2 "$Compiler: unknown compiler."
  107.     exit 1
  108. fi
  109.  
  110. : ${TMP:=$TMPDIR}
  111. : ${TMP:=$HOME}
  112. : ${TMP:=/tmp}
  113.  
  114. # cd to tmpdir so that object files will go there
  115. cd $TMP
  116. tmpbase=$TMP/#mani$$
  117. tmpfile=$tmpbase.c
  118. tmpobj=$tmpbase.o
  119.  
  120. > $tmpfile
  121.  
  122. $Debug && print -ru2 -- "Compiler command line: $Compiler -c $tmpfile"
  123.  
  124. for rword in $($Compiler -c $tmpfile 2>&1); do
  125.     $Debug && print -n -u2 "rword: <$rword>"
  126.     # at&t compiler puts '' around output 
  127.     rword=${rword#\'}
  128.     rword=${rword%%?(\')*( )}
  129.     $Debug && print -u2 "    Cleaned word: <$rword>"
  130.     if [[ "$rword" = -D* ]]; then
  131.     word=$rword
  132.     line="$line${word#-D}"
  133.     let i+=1
  134.     if [ i -eq 4 ]; then
  135.         echo "${line%*( )}"
  136.         line=
  137.         i=0
  138.     fi
  139.     fi
  140. done
  141. rm -f "$tmpfile" "$tmpobj"
  142.  
  143. [ -n "$line" ] && echo "${line%*( )}"
  144.